package com.ltt.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ltt.annotation.NoAuth;
import com.ltt.dao.pojo.FileItems;
import com.ltt.dao.vo.Result;
import com.ltt.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.HashSet;
import java.util.List;

@CrossOrigin
@Api("资源管理")
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @ApiOperation("模糊查询")
    @PostMapping("/findByContent")
    public Result findByContent(@RequestBody String content) {
        System.out.println(content);
        content = content.substring(0, content.length() - 1);
        System.out.println(content);
        HashSet<FileItems> files = resourceService.selectListByLike(content);
        return Result.successWithData(files);
    }

    @ApiOperation("模糊查询s")
    @PostMapping("/findByContents")
    @NoAuth
    public Result findByContents(@RequestBody String content) {
        System.out.println(content);
        JSONObject jsonObject =  JSON.parseObject(content);
        System.out.println(jsonObject.getString("content"));
//        content = content.substring(0, content.length() - 1);
//        System.out.println(content);

        HashSet<FileItems> files = resourceService.findByContents(jsonObject.getString("openid"),jsonObject.getString("name"), jsonObject.getString("content"), jsonObject.getString("subject"));
        return Result.successWithData(files);
    }
}
